module.exports = function stringify(arg) {
  if (null === arg) {
    return 'null';
  } else if (undefined === arg) {
    return 'undefined';
  } else if ('string' === typeof arg) {
    return `"${arg.toString()}"`;
  } else if ('number' === typeof arg) {
    return arg.toString();
  } else if ('boolean' === typeof arg) {
    return arg.toString();
  } else if ('function' === typeof arg) {
    return '[object Function]';
  }

  if (isObject(arg)) {
    let vals = [];

    for (const key in arg) {
      if (arg.hasOwnProperty(key)) {
        vals.push(`"${key}": ${stringify(arg[key])}`);
      }
    }

    return `{${vals.join(', ')}}`;
  }

  if (Array.isArray(arg)) {
    const vals = arg.map((item, index) => {
      return stringify(item);
    });
    return `[${vals.join(', ')}]`;
  }

  return arg;
};

function isObject(arg) {
  return Object.prototype.toString.call(arg) === '[object Object]';
}